<?php include(APP_HOME."/MPDF56/mpdf.php");
if(!class_exists('MAIN_Controller_Action')) Zend_Loader :: loadClass('MAIN_Controller_Action');
class Front_PrintPaymentController extends MAIN_Controller_Action {
	public function printpaymentAction() {
		if(!class_exists('Zend_Auth'))Zend_loader :: loadClass('Zend_Auth');
		$params   = $this->getParams();
		$generic = $this->getGeneric();
		$payment_generic = System_Controller::getGeneric("payment","front");
		$view = $this->_getView();
		$today = getToday();
		$payment_datetime	=	date('Y-m-d H:i:s');
		$auth = Zend_Auth :: getInstance();
    	$identity = $auth->getIdentity();
    	$payment_detail = $generic->getPaymentDetail($params['payment_id']);
    	$preauthData = $payment_generic->getPreAuthById($payment_detail['preauth_id'],$identity->userid);
    	$policyData = $payment_generic->getPolicyById($preauthData['0']['policyid']);
    	$PlanData = $payment_generic->getPlan2catByPlanId($policyData['plan_id']);
    	$claimGetCover	=	$payment_generic->getClaimCover();
		
		$img_path	=	APP_HOME.'/modules/systemapi/templates/default/images';
		//_print($PlanData);exit();
		//$view->assign("paymentId",$params['payment_id']);
		$view->assign("preauthData",$preauthData['0']);
		$view->assign("today",$today);
    	$view->assign("payment_datetime",$payment_datetime);
    	$view->assign("policyData",$policyData);
    	$view->assign("claimGetCover",$claimGetCover);
    	$view->assign("PlanData",$PlanData);
    	$view->assign("payment_detail",$payment_detail);
		//$view->output('pdf/printpayment.tpl');

    	$paymentId	=	$params['payment_id'];
    	$preauth_id	=	$preauthData[0]['preauth_id'];
    	$preauth_datetime	=	$preauthData[0]['preauth_datetime'];
    	//_print($preauthData[0]['preauth_id']);exit();
		 if($policyData['customer_type_desc']	==	"PA"){
			$img = 'title_pa.png';
		} else if($policyData['customer_type_desc']	==	"Health"){
			$img = 'title_health.png';
		} 
		
		$html = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="background-color:#ffffff;">
<div id="wrap_3">
		<div class="title_content_detail">Payment Transection<br><span style="font-size: 16px; font-family: sarabun;">'.$today.'</span></div>
		<div class="line"></div>
		<div id="area_title_description">
			<div class="text_title_description">
				<p>
					<span class="text_black_title">Payment ID: </span><span class="text_red_title">'.$paymentId.'</span>
				</p>
			</div>
			<div class="text_title_images"><img src="'.$img_path.'/'.$img.'"></div>
		</div>
		
		<div class="showdetail"><br>
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family:  sarabun;" bgcolor="#e8e8e8">
				<tr>
					<td class="UnderLine"  colspan="2" align="center"><span class="text_black_bold">ข้อมูล Pre-auth</span></td>
				</tr>
				<tr>
					<td  colspan="2" align="left">&nbsp;</td>
				</tr>
				<tr>
					<td width="350" align="left"><span style="margin-left:20px;">Pre-auth เลขที่ : '.$preauth_id.'</span></td>
					<td width="350" align="left"><span style="margin-left:20px;">วันที่ทำ Pre-auth : '.$preauth_datetime.'</span></td>
				</tr>
				<tr>
					<td align="left"><span style="margin-left:20px;">ชื่อผู้ทำ Pre-auth : '.$identity->user_prename.''.$identity->user_name.'&nbsp;'.$identity->user_surname.'</span></td>
					<td align="left"><span style="margin-left:20px;">รหัสผู้ใช้ : '.$identity->userid.'</span></td>
				</tr>
				<tr>
					<td align="left"><span style="margin-left:20px;">หน่วยงาน : '.$identity->group_name.'</span></td>
					<td align="left"><span style="margin-left:20px;">ตำแหน่ง : '.$identity->usertype_description.'</span></td>
				</tr>
				<tr>
					<td colspan="2" align="left">&nbsp;</td>
				</tr>
			</table>
		<br>
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family: sarabun;" bgcolor="#e8e8e8">
				<tr>
					<td class="UnderLine"  colspan="4" align="center"><span class="text_black_bold">ข้อมูลกรมธรรม์</span></td>
				</tr>
				<tr>
					<td colspan="4" align="center">&nbsp;</td>
				</tr>
				<tr>
					<td width="130" align="right">ชื่อผู้เอาประกัน :</td>
					<td width="220">'.$policyData['name'].'&nbsp;&nbsp;'.$policyData['surname'].'</td>
					<td width="130" align="right">บัตรประชาชน : </td>
					<td width="220">'.$policyData['natid'].'</td>
				</tr>
				<tr>
					<td align="right">เลขที่่กรมธรรม์ :</td>
					<td>'.$policyData['policy_no'].'</td>
					<td align="right">เลขที่บัตรประกัน :</td>
					<td>'.$policyData['cardno'].'</td>
				</tr>
				<tr>
					<td align="right">วันเริ่มคุ้มครอง :</td>
					<td>'.$policyData['effective'].'</td>
					<td align="right">วันสิ้นสุดความคุ้มครอง :</td>
					<td>'.$policyData['expiry'].'</td>
				</tr>
				<tr>
					<td align="right">แผนความคุ้มครอง :</td>
					<td>'.$policyData['plan'].'</td>
					<td align="right">&nbsp;</td>
					<td>&nbsp;</td>
				</tr>';
		
		if($policyData['customer_type_desc']	==	"PA"){
			$html .= '<tr>
								<td align="right">Deductible Remain :</td>
								<td>'.$policyData['deductible'].'</td>
								<td align="right">Co-Payment Remain :</td>
								<td>'.$policyData['copayment'].'</td>
							</tr>';
		} else if($policyData['customer_type_desc']	==	"Health"){
			$html .= '<tr>
								<td align="right">OPD :</td>
								<td>'.$policyData['opd'].'</td>
								<td align="right">ER :</td>
								<td>'.$policyData['er'].'</td>
							</tr>
							<tr>
								<td align="right">OPD คงเหลือ :</td>
								<td>'.$policyData['opdremain'].'</td>
								<td align="right">R&B :</td>
								<td>'.$policyData['rb'].'</td>
							</tr>';
		}		


$html .= '<tr>
					<td colspan="4">&nbsp;</td>
				</tr>
			</table>		
							
			<br>
							
			<table width="700" align="center" border="0" cellpadding="3" cellspacing="0" style="font-size:16px; font-family: sarabun;" bgcolor="#e8e8e8">
				<tr>
					<td class="UnderLine"  colspan="4" align="center"><span class="text_black_bold">ระบุยอดค่าใช้จ่าย</span></td>
				</tr>
				<tr>
					<td  width="25%" align="center">&nbsp;</td>
					<td  width="25%" align="center">&nbsp;</td>
					<td  width="25%" align="center">&nbsp;</td>
					<td  width="25%" align="center">&nbsp;</td>
				</tr>
				<tr>
					<td align="right">Accident Date : </td>
					<td align="left">'.$payment_detail['acc_date'].'</td>	
							<td align="right">Charge : </td>
					<td align="left">'.$payment_detail['charge'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">&nbsp;</td>
					<td align="left">&nbsp;</td>	
							<td align="right">Discount : </td>
					<td align="left">'.$payment_detail['discount'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">Last Accident : </td>
					<td align="left">'.$payment_detail['acc_date'].'</td>	
							<td align="right">Deductible Remain : </td>
					<td align="left">'.$payment_detail['discount'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">&nbsp;</td>
					<td align="left">&nbsp;</td>	
					<td align="right">Deductible Remain : </td>
					<td align="left">'.$payment_detail['deductible'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">Admission Date : </td>
					<td align="left">'.$payment_detail['acc_date'].'</td>	
							<td align="right">Co-Payment Remain : </td>
					<td align="left">'.$payment_detail['copayment'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td colspan="4">&nbsp;</td>
				</tr>
				<tr>
					<td align="right">Cover List :</td>
					<td align="left">'.$payment_detail['payment_type'].'</td>	
					<td align="right"><font color="red">Pre Approved : </font></td>
					<td align="left">'.$payment_detail['pre_approved'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">&nbsp;</td>
					<td align="left">&nbsp;</td>	
					<td align="right"><font color="red">Non Covered :</font></td>
					<td align="left">'.$payment_detail['non_covered'].'&nbsp;บาท</td>	
				</tr>
				<tr>
					<td align="right">สาเหตุการรักษา : </td>
					<td colspan="3" height="100">'.$payment_detail['indication_admit'].'></td>
				</tr>
				
			</table>
		
	</div>
</body>
</html>
';
		
		//$this->render('../../../../MPDF56/mpdf.php');
		$mpdf=new mPDF('utf-8','A4','14','sarabun',5,5,5,5,10,10);
		
		$mpdf->SetDisplayMode('fullpage');
		// LOAD a stylesheet
		$stylesheet = file_get_contents(APP_HOME."/modules/systemapi/templates/default/css/print.css");
		$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text
		
		/* if($policyData['customer_type_desc']	==	"PA"){
			$mpdf->WriteHTML($html);
		} else if($policyData['customer_type_desc']	==	"Health"){
			$mpdf->WriteHTML($html2);
		} */
		
		$mpdf->WriteHTML($html);
		$mpdf->Output(); 
		exit;
		
		}
		
}
?>